//
//  JSON+OC.swift
//  aquariumstudio
//
//  Created by zj on 2022/10/21.
//  Copyright © 2022 LXF. All rights reserved.
//

import Foundation

///  error  -----------Codable to oc, 允许 oc 调用 Codable 的方法
@objc
@objcMembers
public class JSONUtils: NSObject {
    public static func toJsonStr(_ obj:AnyObject)->String?{
        var objT = obj
        
        guard let v = objT as? Encodable else{
            XXLoger.e("no a Encodable")
            return nil;
        }
        
        let jsonEncode = JSONEncoder()
        guard let data = try? jsonEncode.encode(v)else{
            XXLoger.e("jsonEncode.encode error")
            return nil;
        }
        let jsonStr = String.init(data: data, encoding: String.Encoding.utf8)
        return jsonStr
    }
    
    
//    public static func toJsonStrByList(_ obj:[AnyObject])->String?{
//        var objT:[Codable] = []
//
//        obj.forEach { _, o in
//            objT.append(o as! Codable)
//        }
//
//
//        guard let v = objT as? [Encodable] as? Encodable else{
//            log.e("no a Encodable")
//            return nil;
//        }
//
//        let jsonEncode = JSONEncoder()
////        jsonEncode.encode(objT)
//
//        guard let data = try? jsonEncode.encode(v)else{
//            log.e("jsonEncode.encode error")
//            return nil;
//        }
//        let jsonStr = String.init(data: data, encoding: String.Encoding.utf8)
//        return jsonStr
//    }
}
